package com.qfedu.service.impl;

import com.qfedu.mapper.ProjectMapper;
import com.qfedu.mapper.SubitemMapper;
import com.qfedu.model.Project;
import com.qfedu.model.Subitem;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.SubitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class SubitemServiceImpl implements SubitemService {
    @Autowired
    private SubitemMapper subitemMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = subitemMapper.count();
        pageResult.setTotal(count);
        List<Subitem> page = subitemMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addSubitem(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        return subitemMapper.addSubitem(subitem);
    }

    @Override
    public Subitem findById(String sid) {
        return   subitemMapper.findById(sid);
    }

    @Override
    public int editSubitem(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        int i = subitemMapper.editSubitem(subitem);
        return i;
    }

    @Override
    public int deleteBySuid(String suid) {
        return subitemMapper.deleteBySuid(suid);
    }

    @Override
    public List<Subitem> findByPid(int pid) {
        List<Subitem> byPid = subitemMapper.findByPid(pid);
        return byPid;
    }
}